A computer system may manage computer memory dynamically. Dynamic memory management refers to the process by which blocks of memory are allocated temporarily for a specific purpose and then deallocated or freed when no longer needed for that purpose. Free blocks are available for reallocation for another purpose. The process that dynamically manages memory is referred to as the memory manager. The memory that the memory manager manages is referred to as a "heap." A heap is a portion of memory reserved for a program to use for the temporary storage of data structures whose existence or size cannot be determined until the program is running. The program can request a block of free memory having a certain size, use it, and later request that the block be freed. The memory manager allocates differently sized blocks of memory from the heap according to the needs of the requesting program.
When a program needs a block of memory, the program sends a request to the memory manager. The memory manager allocates a block of memory from the heap to satisfy the request and then sends a handle or pointer to the block of memory back to the requesting program. The requesting program can then access the block of memory through the handle or pointer. When the requesting program is finished using the block of memory, the program notifies the memory manager that the block is no longer needed. The memory manager then frees the block of memory to make the block available for allocation. When the memory manager cannot allocate a block of memory to a requesting program (because the heap does not contain a large enough block), the memory manager usually compacts the heap to consolidate all of the free blocks.